home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q0971.dms / q0971.adf / programmer / prog / example_gadgs.dark.c < prev    next >
C/C++ Source or Header  |  1997-04-10  |  6KB  |  241 lines

  1. /*********************************************/
  2. /* File example_gadgs.dark.c                */
  3. /*                         */
  4. /* This exampleshow you how to use different */
  5. /* kind of 'gadgets' available with superdark*/
  6. /*********************************************/
  7.  
  8. #include <exec/types.h>
  9. #include <exec/memory.h>
  10. #include <intuition/intuition.h>
  11. #include <intuition/gadgetclass.h>
  12. #include <graphics/gfx.h>
  13. #include <graphics/gfxbase.h>
  14. #include <dos/dos.h>
  15. #include <graphics/gfxmacros.h>
  16. #include <graphics/rastport.h>
  17. #include <graphics/displayinfo.h>
  18. #include <clib/exec_protos.h>
  19. #include <clib/intuition_protos.h>
  20. #include <clib/dos_protos.h>
  21. #include <clib/graphics_protos.h>
  22. #include <clib/diskfont_protos.h>
  23.  
  24.  
  25. #include "/includes/struct.h"
  26. #include "/includes/tom_gadget.h"
  27. #include "image.h"
  28.  
  29. struct Library        *DiskfontBase;
  30. extern  struct  GfxBase *GfxBase;
  31. extern    struct    appel_proc    *p_data_proc;
  32.  
  33. #define    VOID_ARG    void    __regargs
  34.  
  35. char    *p_text_info=
  36. "This is a part of programmers.doc\n"
  37. "You can see here the different   \n"
  38. "kind of gadgets available\n"
  39. "including 'high level' gadg like\n"
  40. "screen and font\n"
  41. "Note that all corresponding param.\n"
  42. "are saved in the .info file....\n"
  43. "\n"
  44. " @ Thomas Landspurg\n";
  45.  
  46. struct    RastPort    *rp;
  47. struct    Screen        *s;
  48.  
  49. #define    WIDTH    640
  50. #define    HEIGHT    256
  51.  
  52. UWORD  ScreenColors[] = {
  53.     0x000,
  54.     0xFFF,
  55.     0xFE2,
  56.     0x68B,
  57.     0xF90,
  58.     0x0F0,
  59.     0x00F,
  60.     0xF0F,
  61.     0x000 };
  62.  
  63. /* Note that you should put a string with enough place to put the */
  64. /* larger font name                          */
  65. struct    TextAttr myta={"topaz                   ",0,0,0};
  66.  
  67. #define    TAILLE_BUF    100
  68. char    buffer_text[TAILLE_BUF]="";
  69. char *CyclesNames[] = {"This","is","a","list","of","items",NULL};
  70. char *MxNames[]     = {"Item 1","Item 2","Item 3",NULL};
  71. int    __saveds    press_button();
  72.  
  73. struct    tom_gadget    my_gadg[]={
  74.     {"_Button",      BUTTON,  100,10,100, 11,0,0,0,0,(char *)press_button},
  75.     {"Checkbo_x",    CHECKBOX,280,10, 10, 10,0,0,0,0,0},
  76.     {"C_ycle",    CYCLE,   100,25,100, 12,        0,1,0,0,(char *)CyclesNames},
  77.     {"_String",    STRING,  100, 45,250,14,0,TAILLE_BUF,0,0,buffer_text},
  78.     {"_Fonts",    FONT,    100,60,100,12,0,         0,0,0,(char *)&myta},
  79.     {"Scr_een",    SCREEN,  220,60,100,12,0,         0,0,0,0},
  80.     {"Sli_der",    SLIDER,  100,75,200,10,1,0,10,0,0},
  81.     {"_Mx",        MX,     150,90,100,30,0,0, 0,0,(char *)MxNames},
  82.     {"image...",    IMAGE,   250,90, 80,30,0,0,0 ,0,(char *)&image_iffImage},
  83.     {0,        END_LISTE,  0,  0,   0, 0, 0,0,0,0,0}};
  84.  
  85. /********** a little proc to print text on screen ************/
  86. void    my_print(rp,x,y,pc)
  87. struct    RastPort *rp;
  88. int    x,y;
  89. char    *pc;
  90. {
  91.     Move(rp,x,y);
  92.     Text(rp,pc,strlen(pc));
  93. }
  94.  
  95. /* The callback procedure, called when the button is pressed, */
  96. /* Note that this function use the keyword __saved. If you    */
  97. /* don't have this one, try geta4() function              */
  98.  
  99. int    __saveds    press_button(pg,p_t,ctx)
  100. struct    Gadget    *pg;
  101. struct    tom_gadget    *p_t;
  102. struct    contexe    *ctx;
  103. {
  104.     static struct EasyStruct ES={
  105.         sizeof(struct EasyStruct),
  106.         0,"Example",
  107.         "You've pressed the button gadget","I know,thanks",};
  108.  
  109.     EasyRequest(ctx->Wnd, &ES, NULL);
  110.     /* If you return TRUE, this mean that you want to close the */
  111.     /* config window.                        */
  112.     return FALSE;
  113. }
  114.  
  115. /********************* Just to show you something on your screen *****/
  116.  
  117. void    aff_texte(rp)
  118. struct    RastPort *rp;
  119. {
  120.     BYTE    old_flg;
  121.         struct TextFont *myfont;
  122.     int    len,tx,ty,x,y;
  123.     struct    TextExtent    result;
  124.     char    buffer[100];
  125.  
  126.     /* Note that there is SPrintF equivalent in proc_main,    */
  127.     /* so it's better to use this one: SPrintF        */
  128.     SetAPen(rp,1);
  129.  
  130.     SPrintF(buffer,"Cycle value: %ld",my_gadg[2].value);
  131.     my_print(rp,10,20,buffer);
  132.  
  133.     SPrintF(buffer,"String value: %s",my_gadg[3].p_data);
  134.     my_print(rp,10,30,buffer);
  135.  
  136.     SPrintF(buffer,"Slider value: %ld",my_gadg[6].value);
  137.     my_print(rp,10,40,buffer);
  138.  
  139.     SetAPen(rp,1);
  140.     if(DiskfontBase){
  141.            /* We stop CPU watchdog, because opening a textfont can take a */
  142.            /* long time                              */
  143.            old_flg=p_data_proc->enable_watchdog;
  144.            p_data_proc->enable_watchdog=FALSE;
  145.                if (myfont = OpenDiskFont(&myta))
  146.                     {
  147.                         SetFont(rp, myfont);
  148.                             SetSoftStyle(rp,   myta.ta_Style ^ myfont->tf_Style,
  149.                                       (FSF_BOLD | FSF_UNDERLINED | FSF_ITALIC));
  150.             }
  151.            p_data_proc->enable_watchdog=old_flg;
  152.     }
  153.     len=strlen(my_gadg[3].p_data);
  154.     ty=myta.ta_YSize;
  155.     tx=TextLength(rp,my_gadg[3].p_data,len);
  156.     if(tx+10>s->Width){
  157.         tx=s->Width-10;
  158.         len=TextFit(rp,my_gadg[3].p_data,len,&result,NULL,1,s->Width-10,ty);
  159.     }
  160.     x=(s->Width-tx)/2;
  161.     y=(s->Height-ty)/2;
  162.     Move(rp,x,y+ty);
  163.     ty+=8;
  164.     Text(rp,my_gadg[3].p_data,len);
  165.     
  166. }
  167.  
  168. /***************************************************/
  169. /* This is the main entry point of this blanker....*/
  170. /***************************************************/
  171. LONG    dark()
  172. {
  173.   struct    tom_gadget *pg;
  174.   struct    Window    *win;
  175.   WORD        width,height;
  176.  
  177.   pg=&my_gadg[5];
  178.  
  179.   s=0;
  180.   if((GfxBase->LibNode.lib_Version>=37)&&(pg->d3!=0)){
  181.     s=OpenScreenTags(  NULL,
  182.                SA_Width,(ULONG)pg->d1,
  183.                SA_Height,(ULONG)pg->d2,
  184.                            SA_Depth,(ULONG)pg->d3,
  185.                SA_Overscan,(ULONG)pg->value,
  186.                            SA_DisplayID,(ULONG)pg->p_data,
  187.                            SA_Quiet,TRUE,TAG_DONE);
  188.    }
  189.    if(s==0){
  190.     s=OpenScreenTags(NULL,
  191.                            SA_Depth,(ULONG)2,
  192.                SA_Width, (ULONG)320,
  193. /*               SA_Type,CUSTOMSCREEN,*/
  194.                SA_ShowTitle, FALSE,
  195.                            SA_Quiet,TRUE,TAG_DONE);
  196.    }
  197.    if(s){
  198.      SetRGB4 (&s->ViewPort,0,0,0,0);
  199.  
  200.      width=s->Width;
  201.      height=s->Height;
  202.      win=OpenWindowTags(    NULL,
  203.                 WA_Left,    0,
  204.                 WA_Top,        0,
  205.                 WA_Width,    width,
  206.                 WA_Height,    height,
  207.                 WA_CustomScreen,s,
  208.                 WA_Flags,    WFLG_SIMPLE_REFRESH|WFLG_BACKDROP|WFLG_BORDERLESS|WFLG_ACTIVATE,
  209.                 TAG_DONE);
  210.      if(win){
  211.     ClearPtr(win);
  212.     rp = win->RPort;
  213.  
  214.     SetRast(rp,0);
  215.     FreeSprite (0);
  216.     GfxBase->SpriteReserved|=1;
  217.     LoadRGB4(&s->ViewPort,ScreenColors,1<<3);
  218.  
  219.     aff_texte(rp);
  220.         wait_end();
  221.       }
  222.       DCloseScreen(s);
  223.    }
  224.    return(NULL);
  225. }
  226.  
  227. void    proc_init()
  228. {
  229.         DiskfontBase = OpenLibrary("diskfont.library", 37L);
  230.     p_data_proc->code_ret=DARK_WB_20;
  231. }
  232.  
  233. void    proc_save()
  234. {
  235. }
  236. void    proc_end()
  237. {
  238.     if(DiskfontBase)CloseLibrary(DiskfontBase);
  239. }
  240.  
  241.